/* Create cleaned data for reported discontinuities. Cleaning includes replacing
values that were likely off by a decimal place. Use absolute values of disconts
since people often don't care about sign.
*/

cap log close
log using "${logs}/clean_expert_reported_discontinuities.log", replace

* Load DGP SD to compute true discontinuity
use "${dat}/dgp_sd.dta", clear
rename paper playerdgp

* Merge in results
merge 1:m playerdgp using "${dat}/expert_merged_rd_estimates_micro.dta", nogen

destring playerstated_disc_size, replace
destring playerstated_disc_direction, replace

* Not everyone signs their discontinuity. Get direction back from stated discontinuity direction.
replace playerstated_disc_size = abs(playerstated_disc_size) * playerstated_disc_direction

* Create numerical discontinuity
gen discont_raw = playerdisc * sd
label variable discont_raw "Actual discontinuity magnitude (SD * normalized discont. mangitude)"

keep gid pid playerdgp playerstated_disc_size discont_raw playerdisc ///
		D rd_c_mse rd_bc_mse rd_c_ik ///
		rdh_taylor_true_estimate rdh_taylor_rot_estimate
		
* Clean responses which are likely off by a decimal place
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "ADGP1" & pid == "ybn6iquj"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "BDGP2" & pid == "v21oys2x"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "CDGP3" & pid == "f0sr9jlf"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "GDGP7" & pid == "gjhtxgrd"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "GDGP7" & pid == "n2pmcrbo"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "HDGP8" & pid == "b88z6lzy"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "HDGP8" & pid == "f0sr9jlf"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "HDGP8" & pid == "gjhtxgrd"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "HDGP8" & pid == "15rngk7w"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "JDGP10" & pid == "gjhtxgrd"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "JDGP10" & pid == "3ej6wbry"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "JDGP10" & pid == "fa60ygv2"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "JDGP10" & pid == "huo5gimd"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "JDGP10" & pid == "k7uka67h"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "KDGP11" & pid == "5ajemuv7"
replace playerstated_disc_size = playerstated_disc_size / 10 if playerdgp == "KDGP11" & pid == "f0sr9jlf"
replace playerstated_disc_size = playerstated_disc_size * 10 if playerdgp == "BDGP2" & pid == "atij121q"
replace playerstated_disc_size = playerstated_disc_size * 10 if playerdgp == "BDGP2" & pid == "kz5e59yc"
replace playerstated_disc_size = playerstated_disc_size * 10 if playerdgp == "CDGP3" & pid == "li7rb6jp"
replace playerstated_disc_size = playerstated_disc_size * 10 if playerdgp == "DDGP4" & pid == "ix5r2ygz"
replace playerstated_disc_size = playerstated_disc_size * 10 if playerdgp == "GDGP7" & pid == "kz5e59yc"

save "${dat}/expert_reported_discontinuities_cleaned.dta", replace

log close



